// 引入数据验证相关命名空间
using System.ComponentModel.DataAnnotations;

namespace Rabbit3.Api.Dto
{
    /// <summary>
    /// 溯源信息创建DTO - 用于创建新的溯源信息
    /// 包含创建溯源信息所需的基本字段和验证规则
    /// </summary>
    public class CreateTraceabilityDto
    {
        /// <summary>
        /// 商品名称 - 食品的名称，如"有机大米"、"绿色蔬菜"等
        /// </summary>
        [Required(ErrorMessage = "商品名称不能为空")] // 验证：必填字段
        [StringLength(100, ErrorMessage = "商品名称长度不能超过100个字符")] // 验证：最大长度100字符
        public string ProductName { get; set; } = string.Empty;

        /// <summary>
        /// 生产批次 - 产品的生产批次号，用于区分不同批次的产品
        /// </summary>
        [Required(ErrorMessage = "生产批次不能为空")] // 验证：必填字段
        [StringLength(20, ErrorMessage = "生产批次长度不能超过20个字符")] // 验证：最大长度20字符
        public string ProductionBatch { get; set; } = string.Empty;

        /// <summary>
        /// 保质期(天) - 产品从生产日期开始的有效期天数
        /// </summary>
        [Required(ErrorMessage = "保质期不能为空")] // 验证：必填字段
        [Range(1, 3650, ErrorMessage = "保质期必须在1-3650天之间")] // 验证：范围1-3650天
        public int ShelfLifeDays { get; set; }

        /// <summary>
        /// 生产许可证号 - 生产企业的食品生产许可证编号
        /// </summary>
        [Required(ErrorMessage = "生产许可证号不能为空")] // 验证：必填字段
        [StringLength(50, ErrorMessage = "生产许可证号长度不能超过50个字符")] // 验证：最大长度50字符
        public string ProductionLicenseNumber { get; set; } = string.Empty;

        /// <summary>
        /// 生产企业 - 生产该产品的企业名称
        /// </summary>
        [Required(ErrorMessage = "生产企业不能为空")] // 验证：必填字段
        [StringLength(200, ErrorMessage = "生产企业名称长度不能超过200个字符")] // 验证：最大长度200字符
        public string ProductionEnterprise { get; set; } = string.Empty;

        /// <summary>
        /// 封面图URL - 产品封面图片的URL地址，用于展示
        /// </summary>
        [StringLength(500, ErrorMessage = "封面图URL长度不能超过500个字符")] // 验证：最大长度500字符
        public string? CoverImageUrl { get; set; }
    }

    /// <summary>
    /// 溯源信息更新DTO
    /// </summary>
    public class UpdateTraceabilityDto
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        [Required(ErrorMessage = "ID不能为空")]
        public int Id { get; set; }

        /// <summary>
        /// 商品名称
        /// </summary>
        [Required(ErrorMessage = "商品名称不能为空")]
        [StringLength(100, ErrorMessage = "商品名称长度不能超过100个字符")]
        public string ProductName { get; set; } = string.Empty;

        /// <summary>
        /// 生产批次
        /// </summary>
        [Required(ErrorMessage = "生产批次不能为空")]
        [StringLength(20, ErrorMessage = "生产批次长度不能超过20个字符")]
        public string ProductionBatch { get; set; } = string.Empty;

        /// <summary>
        /// 保质期(天)
        /// </summary>
        [Required(ErrorMessage = "保质期不能为空")]
        [Range(1, 3650, ErrorMessage = "保质期必须在1-3650天之间")]
        public int ShelfLifeDays { get; set; }

        /// <summary>
        /// 生产许可证号
        /// </summary>
        [Required(ErrorMessage = "生产许可证号不能为空")]
        [StringLength(50, ErrorMessage = "生产许可证号长度不能超过50个字符")]
        public string ProductionLicenseNumber { get; set; } = string.Empty;

        /// <summary>
        /// 生产企业
        /// </summary>
        [Required(ErrorMessage = "生产企业不能为空")]
        [StringLength(200, ErrorMessage = "生产企业名称长度不能超过200个字符")]
        public string ProductionEnterprise { get; set; } = string.Empty;

        /// <summary>
        /// 封面图URL
        /// </summary>
        [StringLength(500, ErrorMessage = "封面图URL长度不能超过500个字符")]
        public string? CoverImageUrl { get; set; }
    }

    /// <summary>
    /// 溯源信息查询DTO
    /// </summary>
    public class QueryTraceabilityDto
    {
        /// <summary>
        /// 页码
        /// </summary>
        [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]
        public int PageIndex { get; set; } = 1;

        /// <summary>
        /// 每页大小
        /// </summary>
        [Range(1, 100, ErrorMessage = "每页大小必须在1-100之间")]
        public int PageSize { get; set; } = 10;

        /// <summary>
        /// 商品名称搜索
        /// </summary>
        public string? ProductName { get; set; }

        /// <summary>
        /// 生产批次搜索
        /// </summary>
        public string? ProductionBatch { get; set; }

        /// <summary>
        /// 生产企业搜索
        /// </summary>
        public string? ProductionEnterprise { get; set; }

        /// <summary>
        /// 生产许可证号搜索
        /// </summary>
        public string? ProductionLicenseNumber { get; set; }
    }

    /// <summary>
    /// 溯源信息响应DTO
    /// </summary>
    public class TraceabilityResponseDto
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 商品名称
        /// </summary>
        public string ProductName { get; set; } = string.Empty;

        /// <summary>
        /// 生产批次
        /// </summary>
        public string ProductionBatch { get; set; } = string.Empty;

        /// <summary>
        /// 保质期(天)
        /// </summary>
        public int ShelfLifeDays { get; set; }

        /// <summary>
        /// 生产许可证号
        /// </summary>
        public string ProductionLicenseNumber { get; set; } = string.Empty;

        /// <summary>
        /// 生产企业
        /// </summary>
        public string ProductionEnterprise { get; set; } = string.Empty;

        /// <summary>
        /// 封面图URL
        /// </summary>
        public string? CoverImageUrl { get; set; }

        /// <summary>
        /// 信息完善度百分比
        /// </summary>
        public int InformationCompleteness { get; set; }

        /// <summary>
        /// 溯源码
        /// </summary>
        public string? TraceabilityCode { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; }
    }

    /// <summary>
    /// 分页响应DTO
    /// </summary>
    /// <typeparam name="T">数据类型</typeparam>
    public class PagedResponseDto<T>
    {
        /// <summary>
        /// 数据列表
        /// </summary>
        public List<T> Data { get; set; } = new List<T>();

        /// <summary>
        /// 总记录数
        /// </summary>
        public int TotalCount { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages { get; set; }

        /// <summary>
        /// 当前页码
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 每页大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 是否有上一页
        /// </summary>
        public bool HasPreviousPage => PageIndex > 1;

        /// <summary>
        /// 是否有下一页
        /// </summary>
        public bool HasNextPage => PageIndex < TotalPages;
    }
}
